﻿    CREATE OR REPLACE FUNCTION add_student(
        p_full_name         character varying(128),
        p_display_name      character varying(128),
        p_nationality_id    character varying(36)
    )
    RETURNS 
    VARCHAR(36)
    AS
    $$
        /***************************************************************************************************
    **  Function:	public.add_student
    **  Author:		Zhixian Ong
    **
    **  Description:
    **    
    **      Get student with specified name.
    **
    **  Parameters (1):
    **
    **      name    VARCHAR(128)    - name of student to find
    **
    **  Return:
    **
    **      SETOF student
    **
    **  Sample call:
    **
    **      Add 'Zhixian' as a student.
    **      SELECT add_student('Ong Zhi Xian', 'Zhixian', 'S0000000Z')
    **
    **  Modification History:
    **
    **      20140102  Zhixian Ong     - Initial prototype
    ** 
    **  Status:
    **
    **      Dev
    ** 
    ***************************************************************************************************/
    DECLARE
        p_id VARCHAR(36);
            
    BEGIN
            
        --------------------------------------------------------------------------------
        -- Return result
        --------------------------------------------------------------------------------
        INSERT INTO student(
            full_name, 
            display_name, 
            nationality_id
        )
        VALUES (
            p_full_name,
            p_display_name,
            p_nationality_id
        )
        RETURNING id INTO p_id;

        RETURN p_id;

    END;
    $$ LANGUAGE plpgsql;


    